Skip to content

Add multiple C-API version infrastructure and C-API v1.1.0a.1#71

Merged
jbreue16 merged 7 commits intomasterfrom
feature/CAPIversioning
Apr 13, 2026
Merged

Add multiple C-API version infrastructure and C-API v1.1.0a.1#71
jbreue16 merged 7 commits intomasterfrom
feature/CAPIversioning

Conversation

@jbreue16
Copy link
Copy Markdown
Contributor

@jbreue16 jbreue16 commented Mar 20, 2026

This PR adds infrastructure to implement support for multiple C-API versions and v1.1.0a1
The str lookup for the version number should be changed to the type @schmoelder suggested to make comparisons (>, < =) work
to be continued by @AntoniaBerger

@AntoniaBerger
Copy link
Copy Markdown

AntoniaBerger commented Mar 23, 2026

@jbreue16 Is this the pull request you worked on Friday where you added the new C-API versioning to the cpp site? It’s cadet/CADET-Core#366.

Comment thread cadet/cadet_dll.py Outdated
_fields_ = _setup_api(_signatures_)


class CADETAPI_V1_0_0(ctypes.Structure):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, the idea is to call the _set_api function with a string instead of the dictionary of signatures. Then, within _set_api, compare which string is greater.
What’s the benefit of doing it this way?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly, but not using a string but this other type that Jo mentioned which supports comparisons of PEP440 version numbers. The benefit is that we can use this to successively add functions introduced in later (minor or pre-release) versions instead of repeating the whole list

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from packaging.version import Version

latest = "5.1.0"

current = Version("5.2.0a_1")

if current > Version("5.1.0"):
    print("Something that was implemented in 5.2.0")

Comment thread cadet/cadet_dll.py Outdated
class CADETAPI_V1_0_0(ctypes.Structure):
"""Mimic cdtAPIv1.0.0 struct of CADET C-API in ctypes."""
_fields_ = _setup_api("1.0.0")
# class CADETAPI_V1_0_0(ctypes.Structure):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont see a difference here?

Comment thread cadet/cadet_dll.py Outdated
self._cadet_capi_version = cdtGetLatestCAPIVersion().decode('utf-8')

# Check which C-API is provided by CADET (given the current install path)
#current suppurted versions are: 1.0.0 and 1.1.0_a1
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

supported

Comment thread cadet/cadet_dll.py Outdated
if version == Version("1.0.0"):
signatures = dict(CADET_API_V1_SIGNATURES.signatures_1_0_0)

elif version >= Version("1.1.0"):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1.1.0a1 is smaller than v1.1.0

Comment thread cadet/cadet_dll.py Outdated
fields = []

signatures = {}
if version == Version("1.0.0"):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can put a > 1.0.0 && < 2.0.0 here and then not set signatures = dict(CADET_API_V1_SIGNATURES.signatures_1_0_0) for the other cases

Also, we could add a last case with < 1.0.0 || > 1.1.0a1 that raises an exception? @schmoelder

@AntoniaBerger
Copy link
Copy Markdown

AntoniaBerger commented Mar 27, 2026

This would be my suggestions to implement the versioning and timeout in cadet_dll.py.

Key points:

  • Create a dictionary _VERSION_SIGNATURES outside of classes that depends on the version.
  • Add a new attribute _version to c-api classes. The _setup_api() method uses the corresponding _VERSION_SIGNATURES based on the _version.
  • The dll_runner attempts to create the latest c-api version. If unavailable on the cpp site, it defaults to version 1.0.0.

@jbreue16
Copy link
Copy Markdown
Contributor Author

jbreue16 commented Apr 9, 2026

@AntoniaBerger whats missing here?
See cadet/CADET-Core#661

  • The dll_runner attempts to create the latest c-api version. If unavailable on the cpp site, it defaults to version 1.0.0.

With "latest c-api version" you mean the latest one implemented on the cadet-core side, which we read from LATEST_CAPI_VERSION, right?
I think if cadet-python does not implement that version, we should default to the latest version that is <= the CAPI version on the core side, not 1.0.0.
Also, if cadet-core specifies a capi version that has a larger major version number than anything specified here, this should fail?

@AntoniaBerger
Copy link
Copy Markdown

@AntoniaBerger whats missing here? See cadet/CADET-Core#661

Looks good to me. If you want to do this in a separate PR, then timeout.

With "latest c-api version" you mean the latest one implemented on the cadet-core side, which we read from LATEST_CAPI_VERSION, right?

Yes

I think if cadet-python does not implement that version, we should default to the latest version that is <= the CAPI version on the core side, not 1.0.0.

Yes, but in our case, it is 1.0.0, is it not? But yes, it should maybe not be hard-coded.

Also, if cadet-core specifies a capi version that has a larger major version number than anything specified here, this should fail?

I would support two full versions and give a warning that we will not support this lower version in the future.

Copy link
Copy Markdown
Contributor Author

@jbreue16 jbreue16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only a unit test is missing now, locally ive already tested with a cadet simulation for different capi versions

@jbreue16 jbreue16 merged commit 62c64ef into master Apr 13, 2026
5 checks passed
@jbreue16 jbreue16 deleted the feature/CAPIversioning branch April 13, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants